package com.niit.onlinemusic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.niit.onlinemusic.common.R;
import com.niit.onlinemusic.mapper.SongListMapper;
import com.niit.onlinemusic.model.domain.SongList;
import com.niit.onlinemusic.service.SongListService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 歌单业务层实现类
 *
 * @author zuwei522
 * @since 2025/9/19 08:35
 */
@Service
public class SongListServiceImpl extends ServiceImpl<SongListMapper, SongList> implements SongListService {

    private final SongListMapper songListMapper;

    public SongListServiceImpl(SongListMapper songListMapper) {
        this.songListMapper = songListMapper;
    }

    @Override
    public R getSongList(String style) {
        QueryWrapper<SongList> queryWrapper = null;
        // 如果歌单风格不是空，需要设置查询条件
        if (StringUtils.hasLength(style)) {
            queryWrapper = new QueryWrapper<>();
            queryWrapper.like("style", style);
        }
        List<SongList> songList = songListMapper.selectList(queryWrapper);

        return R.success("查询成功", songList);
    }

    @Override
    public R searchSongListByTitle(String title) {
        QueryWrapper<SongList> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("title", title);
        List<SongList> songList = songListMapper.selectList(queryWrapper);
        return R.success("查询歌单成功", songList);
    }

}
